from django.db import models
from tower.models import *
from supplier.models import *

#资产
class Asset(models.Model):
    
    asset_name = models.CharField(max_length = 200,unique = True)#资产名
    price = models.FloatField()#单价
    
#中转站
class Interchange(models.Model):
    '''
        仅仅记录每个房间的资产
    '''
    # 关联tower里的房间
    room = models.ForeignKey(Room,on_delete = models.CASCADE)
    # 关联asset里的资产
    asset = models.ForeignKey(Asset,on_delete = models.CASCADE)
    #关联supplier里的厂家
    vender = models.ForeignKey(Vender,on_delete = models.CASCADE,null = True,blank = True)
    asset_num = models.IntegerField(default = 0)
#需要修理的数量
class Repair(models.Model):
    '''
        资产状态为需要修理
    '''
    #关联中转站
    interchange = models.ForeignKey(Interchange,on_delete=models.CASCADE)
    repair_num = models.IntegerField(default = 0) 


#损坏数量
class Damage(models.Model):
    '''
        资产状态为损坏
    '''
    #关联中转站
    interchange = models.ForeignKey(Interchange,on_delete=models.CASCADE)
    damage_num = models.IntegerField(default = 0) 


#采购
class Purchase(models.Model):
    '''
        采购
        关联房间--需要前端传入楼号楼层
        lr = 录入
        pur = 采购
        room = 存入地点
    '''
    #关联tower里的房间
    save_room = models.ForeignKey(Room,on_delete = models.CASCADE)#存入地址room_num
    #关联login里的用户
    user = models.ForeignKey(User,on_delete = models.CASCADE)#采购人user_name
    #关联asset里的资产
    asset_name = models.ForeignKey(Asset,on_delete=models.CASCADE)
    pur_num = models.IntegerField() 
    lr_date = models.DateTimeField(auto_now_add = True)


#以下是记录表
#记录领用的表
class Receive(models.Model):
    
    receive = models.CharField(max_length = 3000)
    ly_date = models.DateTimeField(auto_now_add = True)

#记录报修表
class RepairForm(models.Model):

    repairform = models.CharField(max_length = 3000)
    bx_date = models.DateTimeField(auto_now_add = True)

#记录报损表
class DamageForm(models.Model):

    damageform = models.CharField(max_length = 3000)
    bs_date = models.DateTimeField(auto_now_add = True)


class InsideReceive(models.Model):
    """
        领用记录表，用来记录领用的各种信息方便查询
            领用的数据以字典传入后台，后台再按格式写入数据库
            需要用到的内容：
                资产名、数量、单价、领用人、记录人、领出位置、放入位置
    """
    receive = models.ForeignKey(Receive, on_delete=models.CASCADE)
    as_name = models.CharField(max_length=100)
    as_num = models.IntegerField()
    jprice = models.FloatField()
    ly_user = models.CharField(max_length=30)
    jl_user = models.CharField(max_length=30)
    out_place = models.CharField(max_length=50)    #领出位置
    in_place = models.CharField(max_length=50)     #放入位置
    ly_date = models.DateTimeField(auto_now_add=True)
    remark = models.CharField(max_length=300)


class RepairsRecord(models.Model):
    """
        报修记录表，记录每一次的报修的单据内容
            	报修以字典的形式传入后台，后台写入数据库
            	需要用到的内容：
                    资产名、数量、报修人、报修房间、备注
                    
    """
    repair = models.ForeignKey(RepairForm, on_delete=models.CASCADE)
    as_name = models.CharField(max_length=100)
    as_num = models.IntegerField()
    bx_user = models.CharField(max_length=30)
    bx_room = models.CharField(max_length=30)
    lr_date = models.DateTimeField(auto_now_add=True)
    remark = models.CharField(max_length=300)


class DamageRecord(models.Model):
    """
        报损记录表，记录每一次的报损的单据内容
            报损以字典的形式传入后台，后台写入数据库
                需要用到的内容
                    	资产名、数量、报损人、报损房间、备注
    """
    damage = models.ForeignKey(DamageForm, on_delete=models.CASCADE)
    as_name = models.CharField(max_length=100)
    as_num = models.IntegerField()
    bs_user = models.CharField(max_length=30)
    bs_room = models.CharField(max_length=30)
    lr_date = models.DateTimeField(auto_now_add=True)
    remark = models.CharField(max_length=300)
    










